package com.yjd.comm.other.uq;

import com.yjd.comm.other.enums.DisposeUqRefTypeEnum;
import com.yjd.comm.other.model.DisposeUqModel;
import com.yjd.comm.other.service.IDisposeUqService;
import com.yjd.comm.util.SpringContextHolder;

/**
 * <b>description</b>：保证业务操作只处理一次的工具类 <br>
 * <b>time</b>：2015-5-12下午1:25:22 <br>
 * <b>author</b>： ready likun_557@163.com
 */
public class DisposeUqUtil {

	public static IDisposeUqService getDisposeUqService() {
		return SpringContextHolder.getBean("disposeUqService");
	}

	/**
	 * 保证唯一性处理,0:已处理过,1:处理成功
	 * 
	 * @param ic
	 * @param disposeUqRefTypeEnum
	 * @param ref_id
	 * @param curtime
	 * @return 
	 * @throws Exception
	 */
	public static int call(IDiposeUqSuccessCall ic, DisposeUqRefTypeEnum disposeUqRefTypeEnum,
			String ref_id, Long curtime) throws Exception {
		DisposeUqModel du = DisposeUqUtil.getDisposeUqService().get(disposeUqRefTypeEnum.name(),
				ref_id);
		if (du == null) {
			du = DisposeUqUtil.getDisposeUqService().insert(
					new DisposeUqModel(disposeUqRefTypeEnum.name(), ref_id, curtime));
			ic.dipose(du);
			return 1;
		} else {
			return 0;
		}
	}
}
